Repository navigation
Conversation
Python 3 sends slices to `Tree.__getitem__`, but its legacy slice implementation only exists in `__getslice__`. `tree[:2]` therefore raises `TypeError`. `reversed(tree)` also raises because it applies `reversed` to a generator. Handle slices through the existing cache-to-object conversion and reverse cached entries before lazy conversion. Add return-type overloads, public API documentation and regressions for ordering, stride, negative/empty ranges, zero steps, independent results and nested paths. Validation: all eight new cases fail on the original CLI implementation. Afterward, the complete tree and typing modules pass 110 tests on each CLI/Gix backend with Python 3.12.14, Git 2.52.0 and GixPython 0.3.0 on Linux. Mypy (40 source files), basedpyright and applicable repository pre-commit hooks pass. Full suites and other platforms were not run. Assisted-by: OpenAI Codex (model: unknown, autonomous)
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the Tree slicing and reverse-iteration changes.
No open issues 🎉
What changed in this PR
This PR fixes two broken Tree sequence operations on Python 3, reusing the existing cached-entry conversion.
Changes:
- Support slicing with independent list results and reverse iteration with lazy object conversion.
- Document both operations and add precise return-type overloads.
- Add regression coverage for slice behavior, object metadata, nested paths, and unchanged source-tree contents.
Reviewer: GitHub Copilot.
| File | Description |
|---|---|
test/test_typing.py |
Adds type-checking assignments for indexing, slicing, and reverse iteration. |
test/test_tree.py |
Tests slice semantics, zero-step rejection, reverse order, and object preservation. |
git/objects/tree.py |
Implements slicing and fixes reverse iteration; adds documentation and overloads. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both
tree[:2]andreversed(tree)raiseTypeErroron Python 3. Slice handling exists only in the legacy__getslice__method, while__reversed__tries to reverse a generator.Handle slices in
__getitem__using the existing cached-entry conversion, and reverse the cached entries before converting them lazily. Add precise return-type overloads, document both operations, and verify object types, paths, modes, IDs and unchanged source-tree contents. This groups the two broken Tree sequence operations in one change.Motivation: Found while inspecting Tree's sequence helpers during caller validation for #2319, as part of @gavenren's requested open-source contribution work. The implementation reuses the existing conversion of Git/Gix results; it adds no independent Git storage behavior.
Validation (Linux, Python 3.12.14, Git 2.52.0, GixPython 0.3.0):
GIT_PYTHON_BACKEND=cli .venv/bin/python test/run-local.py test/test_tree.py test/test_typing.py --no-cov: 110 passed.GIT_PYTHON_BACKEND=gix: 110 passed.mypy: no issues in 40 source files.basedpyright: zero errors or warnings, including the new slice/index result-type assignments.git diff --check: passed.Agent identification: This PR, implementation, tests, commit and description were prepared autonomously by OpenAI Codex in ChatGPT Work Mode, communicating through @gavenren's account. The exact underlying model and reasoning setting are unavailable. No human review, approval or manual testing is claimed.